import re
import time
from selenium import webdriver
from selenium.common import NoSuchWindowException
from selenium.webdriver.common.by import By

name=[]
telephone=[]
Cell_phone=[]
fax=[]
address=[]
people=[]
class Albb:
    # 定义测试方法-账号不存在
    def login(self):
        driver = webdriver.Chrome()  # 创建浏览器驱动对象
        driver.maximize_window()  # 窗口最大化
        driver.get("https://login.1688.com/member/signin.htm")   # 打开首页面
        driver.implicitly_wait(10)  # 隐式等待
        # 扫码登录
        driver.find_element(By.XPATH, '//*[@id="login"]/div[1]/i').click()
        time.sleep(2)
        # 点击服务按钮
        driver.find_element(By.XPATH, '//*[@id="topbar-box"]/div[2]/div/div[1]/div/div[2]').click()
        time.sleep(2)
        # 点击产品按钮
        driver.find_element(By.XPATH, '//*[@id="topbar-box"]/div[2]/div/div[1]/div/div[3]/ul/li[2]/span').click()
        time.sleep(2)
        # 商品输入框
        driver.find_element(By.XPATH, '//*[@id="topbar-box"]/div[2]/div/div[2]/input').send_keys('精密加工件 cnc')
        time.sleep(2)
        # 搜索按钮
        driver.find_element(By.XPATH, '//*[@id="topbar-box"]/div[2]/div/button').click()
        time.sleep(2)
        # 打开新的窗口
        a = ['yichuang2017', 'shop4z14079262175', 'shop0z7671u478921', 'shop8088306j77318', 'shop90608087880z7', 'gangdi', 'shop718i757657038', 'shop8d30l0v838006', 'weiyoujs', 'shop71m9739183980', 'shop70399653r5411', 'shengmaicnc', 'shop6085496150497', 'shop41790112295e5', 'shop06j1003g39202', 'shop1470070306803', 'shop838691v735355', 'shop540ew34248583', 'cfsshilihe', 'shop0662844yxs936', 'shop1j558i09306i1', 'shop8z0101142j2x7', 'shop6tc2469152709', 'hxb868', 'mairte', 'shop12r5978641729', 'shop1475945616116', 'shop9741o0g459g58', 'shengda98', 'dgqianyou', 'baidefuwujin', 'nbkwwj', 'shop630b186l28764', 'shenzhenjiecheng', 'shop106951t6tf261', 'gzlcbj', 'shop255140a08y3o7', 'lishengjingmi', 'shop9c47b40512847', 'shop0w629114302d0', 'shop4151759710474', 'shop4v077h3v10665', 'shop1433782759217', 'shop31p202p5i3046', 'shop06y724p505970', 'yideli2010', 'szhongtailang', 'shop1474648815616', 'shop237y0555u2559', 'hongjiejmwj', 'huixinyuan2007', 'shop3521837o93044', 'shop6872706pb79i2', 'shop03qk3970s6705', 'wxachi', 'shop8594b6kq67002', 'shop698n5139214k5', 'dgsgoodwj', 'shop6u24r371480v4', 'shhehuajx', 'chuntaisuye', 'shop5234b84889148', 'shop1380214730897', 'shop935602y13b8f5', 'xmmxjx', 'wanfuxin', 'shop6753380988424', 'shop6632w4287t745', 'hlcncjg', 'shop69uu613l81882', 'dgzrwjzp', 'shop1359r23202533', 'gearept', 'xhsaybxg', 'shop631si04i17865', 'lmachining', 'shop93683i4607223', 'shop4398712192142', 'zurongwujin', 'shop687v0a1216914', 'shop606850264ylf0', 'shop123b42865pr74', 'shop43646446591t5', 'dgztjmwj', 'heshenjixiejg', 'chenlbxg', 'shop61a7vk608t7t7', 'shop44e496948i046', 'guanyi5188', 'shop6m9om41994667', 'tuoyuewujin', 'shop521p368k168m3', 'dgjnsy', 'dgqianduoduo', 'shop26618388g7330', 'shop71x550950m191', 'shop8y1503y3z4717', 'yhxzhizao', 'hwrobots', 'shop45u7c51660858', 'shop5n6n6i9510463', 'shop967o464k97426', 'shop6539370jut750', 'shop34q5270144cs2', 'ysmetal', 'shop40676va9221h9', 'shop92m820k821793', 'shop538m120515m50', 'shop9d6618130q809', 'shop23460w76697x0', 'shenzhenxuzhen', 'shop8gf5654931809', 'kaihengsujiao', 'szfuwanglong', 'shop3886j6f503449', 'shop982f056475r87', 'shop3p264922924z5', 'shop38468eq107601', 'shop06w4970m27130', 'dxjmjx', 'myzxdeng', 'shop1413391507087', 'huawangjinshu', 'shop77g0416527916', 'xiangchengtech', 'zhonglingjx', 'szxyh888888', 'dglongwang', 'shop1429289554859', 'shop73969681y9nu6', 'shop7d768c2577523', 'gddzwj', 'shop0b6381264q731', 'shop775k8q7725432', 'abprecisionparts', 'shop9419231y51k90', 'shop7v1446389v671', 'shop223bb66q73342', 'shch13816428283', 'zyjmwj', 'shop91o2w455342q1', 'binxiangjingmi', 'shop000525o31t353', 'shop760s9j5579218', None, 'shop14563330am0m6', 'shop62040a6c2c955', 'shop2121c1227bi75', 'shop03236191ik514', 'chuanyunjixie', 'boyuelong', 'shop28872r6r1n315', 'shop09j77p78j9534', 'shop435l2sh961967', 'shop75730ti7610y5', 'shop54dj28k364305', 'shop526119015mgm4', 'mingyixin', 'shop4n462229u4438', 'sanshengguangxue', 'shop9759f2n758055', 'shop17o0xo6366782', 'hongshengjingmi', 'shop860a136887124', 'dgyiweiwujin', 'shop6v617y7324014', 'shop1488935141185', 'heiang', 'shop0001465853t28', 'gangqiwujin', 'xinyunyang', 'shop709r4p7627j87', 'shop12s9452b71h66', 'shop36986r2439407', 'shop1489510749728', 'shop3284s4x686f17', 'shop98348813bf313', 'kwanlonmed', 'xhlfbxg', 'jinduobuxiugang', 'shop7105l93c7u209', 'shop38138h5465490', 'aozhihong', 'szhuayi8899', 'shop60l62867686k8', 'shzc5188', 'shop15979b9b68w78', 'shop1428080761527', 'shop4462r0172z562', 'shop99r8592535008']
        for x in a:
            driver.get('https://{}.1688.com/page/contactinfo.htm?spm=0.0.wp_pc_common_topnav_38229151.0'.format(x))
            time.sleep(2)
            # 隐式等待
            driver.implicitly_wait(10)
            merchant_name_path='//*[@id="bd_0_container_0"]/div/div[2]/div[1]/div[2]'
            merchant_name=driver.find_element(By.XPATH,merchant_name_path).text
            name.append(merchant_name)
            merchant_telephone_path='//*[@id="bd_0_container_0"]/div/div[2]/div[1]/div[3]/div[1]/div[2]'
            merchant_telephone=driver.find_element(By.XPATH,merchant_telephone_path).text
            telephone.append(merchant_telephone)
            merchant_Cell_phone_path='//*[@id="bd_0_container_0"]/div/div[2]/div[1]/div[3]/div[2]/div[2]'
            merchant_Cell_phone=driver.find_element(By.XPATH,merchant_Cell_phone_path).text
            Cell_phone.append(merchant_Cell_phone)
            merchant_fax_path='//*[@id="bd_0_container_0"]/div/div[2]/div[1]/div[3]/div[3]/div[2]'
            merchant_fax=driver.find_element(By.XPATH,merchant_fax_path).text
            fax.append(merchant_fax)
            merchant_address_path='//*[@id="bd_0_container_0"]/div/div[2]/div[1]/div[3]/div[4]/div[2]'
            merchant_address=driver.find_element(By.XPATH,merchant_address_path).text
            address.append(merchant_address)
            merchant_people_path='//*[@id="bd_0_container_0"]/div/div[2]/div[1]/div[4]/div[3]'
            merchant_people=driver.find_element(By.XPATH,merchant_people_path).text
            people.append(merchant_people)
            driver.back()
        driver.quit()
resp=Albb()
resp.login()
print(name)
print(telephone)
print(Cell_phone)
print(fax)
print(address)
print(people)

